﻿namespace Storyteller.Framework.Graphics.Particles.Modifiers
{
	public class AlphaInterpolatorModifier : ParticleModifier
	{
		public float InitialAlpha { get; set; }
		public float MiddleAlpha { get; set; }
		public float FinalAlpha { get; set; }

		public float MiddlePosition { get; set; }

		public override void Process(float deltaSeconds, Particle[] particles, int count)
		{
			for (int i = 0; i < count; i++)
			{
				Particle p = particles[i];

				if (p.Lifetime < MiddlePosition)
				{
					p.Color.A = (InitialAlpha + ((MiddleAlpha - InitialAlpha) * (p.Lifetime / MiddlePosition)));
				}
				else
				{
					p.Color.A = (MiddleAlpha + ((FinalAlpha - MiddleAlpha) * ((p.Lifetime - MiddlePosition) / (1.0f - MiddlePosition))));
				}
			}
		}
	}
}
